var Util = {

	transformTime:function(before){

		var transformTime

		var timeNum

		var Minute = 60

		var Hour = 60*60

		var Day = 60*60*24

		var Month = 60*60*24*30

		var Year = 60*60*24*365

		var now = (new Date()).getTime()

		var time = Math.round((now - before) / 1000)
		//秒级差别按照1分钟算
		if ( Math.floor(time / Minute) == 0 ){

			transformTime = '1 分钟前'

			return transformTime
		//分钟级别
		}else if( Math.floor(time/Hour) == 0 ){

			 timeNum = Math.round(time/Minute)

			 transformTime = timeNum + '分钟前'

			 return transformTime
		//小时级别
		}else if( Math.floor(time/Day) == 0 ){

			 timeNum = Math.round(time/Hour)

			 transformTime = timeNum + '小时前'

			 return transformTime
		//天级别
		}else if( Math.floor(time/Month) == 0 ){

			timeNum = Math.round(time/Day)

			transformTime = timeNum + '天前'

			return transformTime
		//月级别
		}else if (Math.floor(time/Year) == 0){

			timeNum = Math.round(time/Month)

			transformTime = timeNum + '个月前'

			return transformTime

		//年级别
		}else{


			timeNum = Math.round(time/Year)

			transformTime = timeNum + '年前'

			return transformTime

		}

	},


	getPages(totalCount,perCount){

		var pages = (totalCount % perCount) == 0 ? totalCount / perCount : Math.floor(totalCount / perCount) + 1

		return pages
	},

	clearNullArr(arr){

		for(var i = 0; i<arr.length ; i++){

			if(!arr[i] || arr[i] == null || arr[i] == undefined){

				arr.splice(i,1)

				i--
			}
		}

		return arr

	}

}


module.exports = Util